﻿using System;
using Andromeda.Base.Application.UI.Windows.Controls;
using Andromeda.Forge.Common;
using Andromeda.Forge.DataSource.DB;
using ForgeIt.Forms.Project.Datasource.DB;
using ForgeIt.Forms.Solution;
using ForgeIt.UserControls;

namespace ForgeIt.Forms
{
    static class FormFactory
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <param name="connector"></param>
        /// <exception cref="NotSupportedException">Thrown when trying to get a manager that is not yet supported</exception>
        /// <returns></returns>
        internal static BaseManager GetForm(FONode node, Connect connector)
        {
            if (node is FOSolution)
            {
                var form = new ForgeSolutionManager();
                form.DataBind(node as FOSolution);
                return form;
            }
            
            if (node is FODataSourceDBProject)
            {
                var form = new DatabaseProjectManager();
                form.DataBind(node as FODataSourceDBProject);
                return form;
            }
            return null;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <exception cref="NotSupportedException">Thrown when trying to get a manager that is not yet supported</exception>
        /// <returns></returns>
        internal static FO_UserControl GetControl(FONode node)
        {
            FO_UserControl result = null;

            if (node is FOSolution)
            {
                result = new FoSolutionUserControl();
                ((FoSolutionUserControl)result).DataBind(node as FOSolution);
            }
            if (node is FODataSourceDBProject)
            {
                result = new FoDatasourceDbProjectUserControl();
                ((FoDatasourceDbProjectUserControl)result).DataBind(node as FODataSourceDBProject);
            }

            return result;
        }
    }
}
